// pages/gangManage/productPutaway/productPutaway.js

const app = getApp()
var util = require('../../../utils/util.js')
var http = require('../../../utils/server.js')

Page({
  data: {
    productList: [],
    menuData: [],
    selectMenu: {
      current: -1,
      selectedCurrent: -1,
      selectedChild: [],
      selectedChildName: [],
      isShow: false,
    }
  },
  onLoad: function() {
    this.getData()
  },
  getData:function(){
    var that = this
    //商品列表
    http.post({
      url: "product/putawayList",
      type: ''
    }, function (data) {
      console.log('商品列表', data)
      that.setData({
        productList: data
      })
    })
    //筛选条件
    http.post({
      url: "product/getFilterData"
    }, function (data) {
      console.log('筛选条件', data)
      that.setData({
        menuData: data
      })
    })
  },
  menuTap: function(e) {
    var selectMenu = this.data.selectMenu;
    selectMenu.isShow = !selectMenu.isShow;
    if (selectMenu.current != e.currentTarget.dataset.index)
      selectMenu.isShow = true;
    selectMenu.current = e.currentTarget.dataset.index;
    this.setData({
      selectMenu: selectMenu
    })
  },

  childMenuTap: function(e) {
    var that = this;
    var selectMenu = this.data.selectMenu;
    selectMenu.isShow = false;
    selectMenu.selectedCurrent = e.currentTarget.dataset.pid;
    selectMenu.selectedChild[selectMenu.selectedCurrent] = e.currentTarget.dataset.index;
    selectMenu.selectedChildName[selectMenu.selectedCurrent] = e.currentTarget.dataset.name;
    this.setData({
      selectMenu: selectMenu
    })
    //商品列表
    http.post({
      url: "product/putawayList",
      // classify: selectMenu.selectedChild[0],
      type: selectMenu.selectedChild[0],
      brand: selectMenu.selectedChild[1],
    }, function(data) {
      console.log('商品列表', data)
      that.setData({
        productList: data
      })
    })

  },
})